import 'package:scoped_model/scoped_model.dart';
import 'package:crm/model/ClientManager/contact_info_model.dart';
import 'package:crm/model/ClientManager/client_info_model.dart';
import 'package:crm/model/Company/company_category_model.dart';

class MainModel extends Model
    with
        LoginScopedModel,
        ClientManagerScopedModel,
        ContactManagerScopedModel,
        IndustryCategoryManager {
  MainModel of(context) => ScopedModel.of<MainModel>(context);
}

/// 登录状态管理
class LoginScopedModel extends Model {
  String passwordText = '';

  void changePasswordText(String pass) {
    passwordText = pass;
    notifyListeners();
  }

  String passwordGesture = '';

  void changePasswordGesture(String pass) {
    passwordGesture = pass;
    notifyListeners();
  }
}

///
class ClientManagerScopedModel extends Model {
  bool clientManagerListIsArrangement; // 默认收起

  changeClientManagerListStyle(bool listStyle) {
    clientManagerListIsArrangement = listStyle;
  }

  ClientInfoModel client = ClientInfoModel.fromJson({});

  initClientInfo() {
    client = ClientInfoModel.fromJson({});
  }
}

class ContactManagerScopedModel extends Model {
  List<ContactInfoModel> contactsInfoList = List<ContactInfoModel>();

  initContactInfoList() {
    contactsInfoList = List<ContactInfoModel>();
    notifyListeners();
  }

  addContact(ContactInfoModel contactInfo) {
    contactsInfoList.add(contactInfo);
    notifyListeners();
  }

  addContactAll(List<ContactInfoModel> contactsInfo) {
    contactsInfoList.addAll(contactsInfo);
    notifyListeners();
  }

  removeContact(ContactInfoModel contactInfo) {
    contactsInfoList.remove(contactInfo);
    notifyListeners();
  }

  removeContactAt(int index) {
    contactsInfoList.removeAt(index);
    notifyListeners();
  }
}

class IndustryCategoryManager extends Model {
  int selIndustryCategoryIndex = 0;
  CompanyCategoryInfoModel saveIndustryCategory =
      CompanyCategoryInfoModel.fromJson({});

  initIndustryCategory() {
    selIndustryCategoryIndex = 0;
    saveIndustryCategory = CompanyCategoryInfoModel.fromJson({});
  }

  saveIndustryCategoryAt(int index, CompanyCategoryInfoModel industryCategory) {
    selIndustryCategoryIndex = index;
    saveIndustryCategory = industryCategory;

    notifyListeners();
  }
}
